package sm.pzavoli.mercato.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

import sm.pzavoli.std.ProprietaAttributo;
import sm.pzavoli.std.StdPojo;

public class TickerStorico extends StdPojo {
	static HashMap<String, ProprietaAttributo> m_pattributi = new HashMap<String, ProprietaAttributo>();
	public static final String CSZ_ID = "_id";
	public static final String CSZ_NOME = "Nome";
	public static final String CSZ_SIMBOLO = "Simbolo";
	static {
		m_pattributi.put(CSZ_ID, new ProprietaAttributo(CSZ_ID));
		m_pattributi.put(CSZ_NOME, new ProprietaAttributo(CSZ_NOME));
		m_pattributi.put(CSZ_SIMBOLO, new ProprietaAttributo(CSZ_SIMBOLO));		
	}

    public Date getDate() {
        return date;
    }

    public double getOpen() {
        return open;
    }

    public double getHigh() {
        return high;
    }

    public double getLow() {
        return low;
    }

    public double getClose() {
        return close;
    }

    public int getVolume() {
        return volume;
    }

    private Date date;
    private double open;
    private double high;
    private double low;
    private double close;
    private int volume;


    /*
     * Constructor that dates the Date as a string.
     */
    public TickerStorico(String date, double open, double high, double low, double close, int volume) {
        this.date = extractDate(date);
        this.open = open;
        this.high = high;
        this.low = low;
        this.close = close;
        this.volume = volume;
    }

    public void dumpData() {
        System.out.println("->" + date + ":" + open + "," + high + "," + low + "," + close + "," + volume);
    }


    public Date extractDate(String aDateStr) {

        String pattern = "yyyy-MM-dd";
        Date date = null;

        SimpleDateFormat format = new SimpleDateFormat(pattern);
        try {
            date = format.parse(aDateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
